package com.wenbing.miio.mi;

import java.nio.ByteBuffer;

public class MessageFrame {
    /**
     * 魔数
     */
    public static final short MAGIC = 0x2131;//2B

    /**
     * 头部长度
     */
    public static final int HEAD_LENGTH = 32;//2B

    /**
     * 校验和长度
     */
    public static final int CHECKSUM_LENGTH = 16;

    public static final int FLAGS_HELLO = 0xffffffff;


    /**
     * 数据长度
     */
    //private int length ;            //2B

    /**
     * flags
     */
    private int flags ;               //4B

    /**
     * 设备id
     */
    private int deviceId;           //4B

    /**
     * 时间戳
     */
    private long stamp;              //4B

    /**
     * token
     */
    private byte[] checksum;           //16B token/checkSum

    /**
     * 负载
     */
    private ByteBuffer payload;

    /*public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }*/

    public int getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(int deviceId) {
        this.deviceId = deviceId;
    }

    public long getStamp() {
        return stamp;
    }

    public void setStamp(long stamp) {
        this.stamp = stamp;
    }

    public byte[] getChecksum() {
        return checksum;
    }

    public void setChecksum(byte[] checksum) {
        this.checksum = checksum;
    }

    public void setFlags(int flags) {
        this.flags = flags;
    }

    public int getFlags() {
        return flags;
    }

    public void setPayload(ByteBuffer payload) {
        this.payload = payload;
    }

    public ByteBuffer getPayload() {
        return payload;
    }

    public boolean is(int flags) {
        return this.flags == flags;
    }
}
